package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/operation/serve")
@Slf4j
@RequiredArgsConstructor
public class ServeController {
    private final IServeService serveService;

    @GetMapping("/page")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO pageQueryReqDTO){
        log.info("区域服务分页查询:{}",pageQueryReqDTO.getRegionId());
        return serveService.page(pageQueryReqDTO);
    }

    @PostMapping("/batch")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveList){
        log.info("区域服务新增:{}",serveList);
        serveService.ListBatch(serveList);
    }

    @PutMapping("/{id}")
    public void update(@PathVariable("id") Long id,
                       @RequestParam("price")BigDecimal price){
        log.info("区域服务{}价格修改为:{}",id,price);
        serveService.update(id,price);
    }

    @PutMapping("/onSale/{id}")
    public void onSale(@PathVariable("id") Long id){
        log.info("区域服务{}启用",id);
        serveService.activate(id);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Long id){
        log.info("区域服务{}删除",id);
        serveService.removeById(id);
    }

    @PutMapping("/offSale/{id}")
    public void offSale(@PathVariable("id") Long id){
        log.info("区域服务{}禁用",id);
        serveService.disable(id);
    }

    @PutMapping("/onHot/{id}")
    public void onHot(@PathVariable("id") Long id){
        log.info("开启热门开发:{}",id);
        serveService.onHot(id);
    }
    @PutMapping("/offHot/{id}")
    public void offHot(@PathVariable("id") Long id){
        log.info("取消热门开发:{}",id);
        serveService.offHot(id);
    }
}
